#ifndef __GWMESSAGEMAP_HPP__
#define __GWMESSAGEMAP_HPP__

#include <stdlib.h>
#include "../util/gwnulltype.h"
#include "../util/gwcommon.h"


/**
*@file       gwmessagemap.hpp
*@brief      message mapping
*
*@author     graywind
*@version    1.0.0.0
*@data       2012/01/04
*/

        ///message mapping
        template<typename MessageType, typename ParamType = gwBedrockUtil::gwNullType>
        class gwMessageMap;
        ///message port
        class gwMessagePort;


        ///message mapping
        template<typename MessageType, typename ParamType>
        class gwMessageMap
        {
        public:
                static void HandleMessage( PARAM_IN  void* messagePtr, PARAM_INOUT  ParamType* paramPtr)
                {
                        std::abort();
                }
        };

///@brief     use this macro after message handler defined, implement message mapping
#define RegisterHandler_2(message_type, param, handler)\
template<>\
class  gwMessageMap<message_type, param> : public handler\
{\
};


        ///message mapping
        template<typename MessageType>
        class gwMessageMap<MessageType, gwBedrockUtil::gwNullType>
        {
        public:
                static void HandleMessage(PARAM_IN void* messagePtr)
                {
                        std::abort();
                }
        };

///@brief     use this macro after message handler defined, implement message mapping
#define RegisterHandler(message_type,   handler)\
template<>\
class  gwMessageMap<message_type, gwBedrockUtil::gwNullType> : public handler\
{\
};

        ///process message from this message port
        class gwMessagePort
        {
        public:
                template<typename MessageType>
                static void ProcessMessage(PARAM_IN MessageType* messagePtr)
                {
                        gwMessageMap<MessageType>::HandleMessage(messagePtr);
                }

                template<typename MessageType, typename ParamType>
                static void ProcessMessage(PARAM_IN MessageType* messagePtr, PARAM_INOUT ParamType* paramPtr)
                {
                        gwMessageMap<MessageType, ParamType>::HandleMessage(messagePtr, paramPtr);
                }
        };

#endif
